﻿/*
Post-Deployment Script Template							
--------------------------------------------------------------------------------------
 This file contains SQL statements that will be appended to the build script.		
 Use SQLCMD syntax to include a file in the post-deployment script.			
 Example:      :r .\myfile.sql								
 Use SQLCMD syntax to reference a variable in the post-deployment script.		
 Example:      :setvar TableName MyTable							
               SELECT * FROM [$(TableName)]					
--------------------------------------------------------------------------------------
*/
SET IDENTITY_INSERT Auth.AuthenticationType ON;
GO

IF (SELECT COUNT(*) FROM Auth.AuthenticationType WHERE AuthenticationTypeName = 'EventHandler') = 0
  INSERT INTO Auth.AuthenticationType (AuthenticationTypeID, AuthenticationTypeName)
  VALUES (1, 'EventHandler');

IF (SELECT COUNT(*) FROM Auth.AuthenticationType WHERE AuthenticationTypeName = 'OpenID') = 0
  INSERT INTO Auth.AuthenticationType (AuthenticationTypeID, AuthenticationTypeName)
  VALUES (2, 'OpenID');

IF (SELECT COUNT(*) FROM Auth.AuthenticationType WHERE AuthenticationTypeName = 'LiveID') = 0
  INSERT INTO Auth.AuthenticationType (AuthenticationTypeID, AuthenticationTypeName)
  VALUES (3, 'LiveID');
GO

SET IDENTITY_INSERT Auth.AuthenticationType OFF;
GO

SET IDENTITY_INSERT Event.AttendeeListVisibility ON;
GO

IF (SELECT COUNT(*) FROM Event.AttendeeListVisibility WHERE AttendeeListVisibilityDescription = 'Public') = 0
  INSERT INTO Event.AttendeeListVisibility (AttendeeListVisibilityID, AttendeeListVisibilityDescription) VALUES (1, 'Public');

IF (SELECT COUNT(*) FROM Event.AttendeeListVisibility WHERE AttendeeListVisibilityDescription = 'Public') = 0
  INSERT INTO Event.AttendeeListVisibility (AttendeeListVisibilityID, AttendeeListVisibilityDescription) VALUES (2, 'Viewable to attendees');

IF (SELECT COUNT(*) FROM Event.AttendeeListVisibility WHERE AttendeeListVisibilityDescription = 'Public') = 0
  INSERT INTO Event.AttendeeListVisibility (AttendeeListVisibilityID, AttendeeListVisibilityDescription) VALUES (3, 'Viewable to paid attendees');

IF (SELECT COUNT(*) FROM Event.AttendeeListVisibility WHERE AttendeeListVisibilityDescription = 'Public') = 0
  INSERT INTO Event.AttendeeListVisibility (AttendeeListVisibilityID, AttendeeListVisibilityDescription) VALUES (4, 'Private');
GO

SET IDENTITY_INSERT Event.AttendeeListVisibility OFF;
GO

-- Grant permissions to stored procedures
GRANT EXECUTE ON Auth.CreateNewAccount TO EventHandlerWeb;
GRANT EXECUTE ON Auth.DeleteAccount TO EventHandlerWeb;
GRANT EXECUTE ON Auth.GetUserByAccountID TO EventHandlerWeb;
GRANT EXECUTE ON Auth.GetUserByUserName TO EventHandlerWeb;
GRANT EXECUTE ON Auth.UpdateAccount TO EventHandlerWeb;
GRANT EXECUTE ON Event.AddSchedule TO EventHandlerWeb;
GRANT EXECUTE ON Event.CancelAttendance TO EventHandlerWeb;
GRANT EXECUTE ON Event.CreateInvitation TO EventHandlerWeb;
GRANT EXECUTE ON Event.CreateNewEvent TO EventHandlerWeb;
GRANT EXECUTE ON Event.CreateNewLocation TO EventHandlerWeb;
GRANT EXECUTE ON Event.DeleteEvent TO EventHandlerWeb;
GRANT EXECUTE ON Event.GetEvent TO EventHandlerWeb;
GRANT EXECUTE ON Event.RSVP TO EventHandlerWeb;
GRANT EXECUTE ON Event.UpdateEvent TO EventHandlerWeb;
GRANT EXECUTE ON Event.UpdateInvitation TO EventHandlerWeb;
GRANT EXECUTE ON Event.UpdateLocation TO EventHandlerWeb;
GRANT EXECUTE ON Event.UpdateSchedule TO EventHandlerWeb;
GO